import {Component, OnInit} from '@angular/core';

@Component({
    selector: 'app-search-engines',
    templateUrl: './search-engines.component.html',
    styleUrls: ['./search-engines.component.less']
})
export class SearchEnginesComponent implements OnInit {
    public tagIndex = 0;
    public searchValue: string;

    constructor() {
    }

    ngOnInit() {
    }

    searchTags(index) {
        this.tagIndex = index;
    }

    search() {
        let url;
        if (!this.searchValue) {
            this.searchValue = '';
        }
        switch (this.tagIndex) {
            case 0:
                url = 'https://www.baidu.com/s?ie=utf-8&wd=' + this.searchValue;
                break;
            case 1:
                url = 'https://www.google.com/search?q=' + this.searchValue;
                break;
            case 2:
                url = 'https://cn.bing.com/search?q=' + this.searchValue;
                break;
            case 3:
                url = 'https://www.sogou.com/web?query=' + this.searchValue;
                break;
        }
        window.open(url);
    }

    keyDown(e) {
        if (e.keyCode === 13) {
            this.search();
        }
    }
}
